package com.wennimei.controllers.admin;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import org.springframework.beans.factory.annotation.Autowired;

import com.wennimei.dao.AdminDAO;
import com.wennimei.service.UserService;

@Path("userAdmin")
public class UserAdminController {

    @Autowired
    private UserService userService;

    @Autowired
    private AdminDAO adminDAO;

    @Get("index")
    public String index() {

        return "useradmin";
    }

    @Post("add")
    public String add(@Param("u") String username, @Param("p") String password,
            @Param("regType") String regType,
            @Param("renrenId") String renrenId,
            @Param("weixinId") String weixinId,
            @Param("sinawbId") String sinawbId,
            @Param("country") String country,
            @Param("province") String province, @Param("city") String city,
            @Param("sex") String sex) {
        if (this.adminDAO.isAdmin(username, password) == 0)
            return "@无权限";
        this.userService.insertUser(regType, renrenId, weixinId, sinawbId,
                country, province, city, sex);

        return "r:/admin/userAdmin";
    }
}
